package i2.application.checklist.scenario;

import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.matchers.JUnitMatchers.containsString;
import i2.application.checklist.entities.Application;
import i2.application.checklist.selenium.pages.administration.applications.CreateApplicationPage;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.PageFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdministrationCreateApplicationScenario {

	private static final Logger logger = LoggerFactory.getLogger(AdministrationCreateApplicationScenario.class);
	private CreateApplicationPage page;

	@Before
	public void openTheBrowser() {
		page = PageFactory.initElements(new HtmlUnitDriver(), CreateApplicationPage.class);
		page.open("http://localhost:8080/checklist/creerApplication");
	}

	@Test
	public void createApplication() {
		logger.info("begin createApplication()");
		Application application = new Application();
		application.setNom("TEST");
		application.setDescription("DESCRIPTION TEST");

		page.create(application);

		assertThat(page.getTitle(), containsString("CheckList"));
		assertTrue("il y a des erreurs dans la page",page.getErrors().isEmpty());
	}

	@After
	public void closeTheBrowser() {
		page.close();
	}
}
